

package com.hazelcast.spi.impl.eventservice.impl.operations;

import com.hazelcast.internal.cluster.ClusterService;
import com.hazelcast.spi.impl.eventservice.impl.Registration;
import com.hazelcast.spi.impl.operationservice.Operation;

import java.util.function.Supplier;

/**
 * Supplier that creates {@link RegistrationOperation}s for a listener registration.
 */
public class RegistrationOperationSupplier implements Supplier<Operation> {
    private final Registration reg;
    private final int orderKey;
    private final ClusterService clusterService;

    public RegistrationOperationSupplier(Registration reg, ClusterService clusterService) {
        this(reg, -1, clusterService);
    }

    public RegistrationOperationSupplier(Registration reg, int orderKey, ClusterService clusterService) {
        this.reg = reg;
        this.orderKey = orderKey;
        this.clusterService = clusterService;
    }

    @Override
    public Operation get() {
        return new RegistrationOperation(reg, orderKey, clusterService.getMemberListVersion());
    }
}
